package Operation;

import Book.BookList;

import java.util.Scanner;

public class DelOperation implements ioperation{
    public void work(BookList bookList) {
        System.out.println("删除图书！");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的书籍名称：");
        String name = scanner.nextLine();

        //遍历书架判断是否有需要删除的书
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(name.equals(bookList.getBooks(i).getName())){
                //有需要删除的书，进行删除并且后面书往前移
                int index = i;
                for (int j = 0; j < bookList.getUsedSize()-1; j++) {
                    //自需要删除的书位置后后面书往前整体移一个位置
                    bookList.setBooks(bookList.getBooks(j+1),j);
                    //成功删掉目标书，并且书架书总数减一，并且直接退出
                    bookList.setUsedSize(bookList.getUsedSize()-1);
                    System.out.println("ok了给您删了好家伙");
                    return;
                }

            }
        }
        System.out.println("抱歉！未找到这本书！");

    }
}
